<template>
  <div class="container" style="width:100%;height:100%;background:#f3f3f3;">
    <van-nav-bar :title="title" fixed class="titleStyle" left-arrow @click-left="onClickLeft" />
    <!-- 工序检列表-->
    <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
      <van-list v-model="loading" :finished="finished" finished-text="已全部加载完成" class="van-clearfix" :immediate-check="false" @load="onLoad">
        <div class="contentBox">
          <div v-for=" item in list" :key="item.purchaseId" class="listDiv">
            <van-row style="width:100%;height:100%;">
              <div class="checkList">
                <h1><span>{{ item.materialName }}{{ item.materialCode !== '' ? '【' + item.materialCode + '】': '' }}</span><b>半成品/成品</b></h1>
                <ul>
                  <li>
                    <b>工单号：</b>
                    <span>{{ item.workOrderNo }}</span>
                  </li>
                  <li>
                    <b>计划单号：</b>
                    <span>{{ item.planNo }}</span>
                  </li>
                  <li>
                    <b>计划批次号：</b>
                    <span>{{ item.planBatchNo }}</span>
                  </li>
                  <li>
                    <b>合并计划批次号：</b>
                    <span>{{ item.planMergeBatchNo }}</span>
                  </li>
                  <li>
                    <b>工艺版本：</b>
                    <span>{{ item.routeVersion }}</span>
                  </li>
                  <li>
                    <b>加工设备：</b>
                    <span>{{ item.proEquipName }}{{ item.proEquipCode !== '' ? '【' + item.proEquipCode + '】': '' }}</span>
                  </li>
                  <li>
                    <b>工序：</b>
                    <span>{{ item.procedureName }}</span>
                  </li>
                  <li>
                    <b>材料批次：</b>
                    <span>{{ item.batch }}</span>
                  </li>
                  <li>
                    <b>加工日期：</b>
                    <span>{{ item.proProcessDate }}</span>
                  </li>
                  <li>
                    <b>加工人：</b>
                    <span>{{ item.proUserName }}</span>
                  </li>
                  <li>
                    <b>送检数量：</b>
                    <span>{{ item.reportNum }}</span>
                  </li>
                  <li>
                    <b>送检时间：</b>
                    <span>{{ item.reportDate }}</span>
                  </li>
                </ul>
                <div class="checkListBtn">
                  <van-button v-if="item.receiveStatus === 1" type="info" @click="InspectionEntry(item)">检验录入</van-button>
                  <van-button v-else type="info" style="margin-right:10px;" @click="receiveBtn(item)">接收</van-button>
                </div>
              </div>
            </van-row>
          </div>
        </div>
      </van-list>
    </van-pull-refresh>
    <div v-show="list.length === 0 && loading === false" class="noDataAvailable noDataAvailable3" />
  </div>
</template>
<script>
export default {
  name: 'FirstInspection',
  data () {
    return {
      show: false,
      title: localStorage.getItem('name'),
      code: localStorage.getItem('code'),
      search: {
        current: 1,
        size: 5
      },
      list: [],
      pages: 0,
      total: 0,
      loading: false,
      finished: false,
      isLoading: false
    }
  },
  created () {
    // this.search.proBatchNo = this.$route.query.code
  },
  mounted () {
    this.getListInfo()
  },
  methods: {
    /* 获取页面数据 */
    async getListInfo (page) {
      if (page) this.search.current = page
      if (+page === 1) this.list = []
      this.loading = true
      const res = await this.$axios.post('/dobo-product/pad/procedure/list', this.search)
      if (res.data.code === 200) {
        this.show = false
        const list = []
        res.data.data.list.filter(item => {
          list.push(item)
        })
        this.list = this.list.concat(list) // 去重 合并
        const hash = {}
        // 数组去重
        this.list = this.list.reduce((preVal, curVal) => {
          /* eslint-disable-next-line */
                      hash[curVal.id]
            ? ''
            : (hash[curVal.id] = true && preVal.push(curVal))
          return preVal
        }, [])
        this.total = res.data.data.total
        this.loading = false
        if (+this.list.length === +this.total) {
          this.finished = true
        }
      }
    },
    //   触底加载
    onLoad () {
      setTimeout(() => {
        if (this.list.length < this.search.current) {
          this.finished = true
          return
        }

        if (this.list.length === this.total) {
          this.finished = true
          return
        }
        let num
        num = this.search.current
        num++
        this.getListInfo(num)
      }, 1000)
    },
    //  下拉刷新
    onRefresh () {
      setTimeout(() => {
        this.list = []
        this.total = 0
        this.finished = false
        this.getListInfo(1)
        this.isLoading = false
      }, 500)
    },
    /* 检验录入 */
    InspectionEntry (row) {
      this.$router.push('/processCheckInput')
      this.$store.commit('getDate', row)
    },
    async receiveBtn (row) {
      await this.$axios.post(`/dobo-product/pad/procedure/receive?id=${row.id}`).then(res => {
        if (res.data.code === 200) {
          this.$dialog
            .alert({
              title: '提示',
              message: '接收成功!'
            })
            .then(() => {
              this.getListInfo(1)
            })
            .catch(() => {})
        }
      })
    },
    // 返回
    onClickLeft () {
      this.$router.push('/Task')
    }
  }
}
</script>
<style lang='scss' scoped>
.container{
}
</style>
<style lang='scss'>

</style>
